package org.mtdownload.app;

import javax.swing.JTabbedPane;

import org.mtdownload.chartview.MTDownloadChartView;
import org.mtdownload.download.DownloadManager;
import org.mtdownload.download.DownloadTask;
import org.mtdownload.infoview.MTDownloadInfoView;
import org.mtdownload.listview.DownloadsListSelectionListener;
import org.mtdownload.progressview.MTDownloadProgressView;

public class InfoTabsView extends JTabbedPane {

	private static final long serialVersionUID = 3617289047400133938L;
	private DownloadTask curentlySelectedTask=null;
	private InfoTabsDownloadListSelectionListener listener=new InfoTabsDownloadListSelectionListener();
	
	private MTDownloadProgressView progressView=new MTDownloadProgressView(); 
	private MTDownloadInfoView infoView=new MTDownloadInfoView();
	private MTDownloadChartView chartView=new MTDownloadChartView();
	
	public InfoTabsView() {
		super();
		init();
	}
	
	private void init(){	
		addTab("Progress",progressView);
		addTab("Detailed info",infoView);
		addTab("Chart view",chartView);
	}

	public DownloadsListSelectionListener getDownloadsListSelectionListener(){
		return listener;
	}
	
	class InfoTabsDownloadListSelectionListener implements DownloadsListSelectionListener{
		public void downloadsSelected(int[] rows) {
			if(rows==null||rows.length==0){
				curentlySelectedTask=null;				
			}else{
				curentlySelectedTask=DownloadManager.getDownloadTaskAt(rows[0]);
			}
			progressView.setCurentlySelectedTask(curentlySelectedTask);
			infoView.setCurentlySelectedTask(curentlySelectedTask);
			chartView.setCurentlySelectedTask(curentlySelectedTask);
		}		
	}
	
}
